//
//  HomeViewController.m
//  YunGui
//
//  Created by wmm on 15/11/5.
//  Copyright © 2015年 hanen. All rights reserved.
//

#import "VisitViewController.h"
#import "VisitListCell.h"
#import "VisitInfoViewController.h"
#import "AddVisitViewController.h"

#import "SideMenuUtil.h"

#import "ManagerNoticeBtnView.h"
#import "TopBtn.h"
#import "MJRefresh.h"
#import "VisitListCell2.h"
#import "OfficeModel.h"
#import "OficeTableViewCell.h"
#import "HYMDatePicker.h"
#import "CityPersonModel.h"
#import "PersonnelstatisticsViewControl.h"
#import "PersonnelViewController.h"

#define LableHeight 20.0f
#define Height(msg) [UIView getHeight:msg]
#define Width(msg) [UIView getWidth:msg]
#pragma mark -
#pragma mark Constants

//static const CGFloat MJDuration = 2.0;

@interface VisitViewController ()<HYMDatePickerDelegate,ManagerNoticeBtnViewDelegate,UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate,UIViewPassValueDelegate>
{
//    float lastContentOffset;
    
    ManagerNoticeBtnView *btnView;
    
    UITableView       *_tableView;
    
    UIButton  *_newSubdistrictBtn;
    UIButton *righB;
    
    int  role ;
    NSMutableArray *mineArray;
    NSMutableArray *expandArray;
    NSMutableArray *visitListArray;
    int  type;//区分点击的各个部分
    
    NSString * SelectedType;
    int selectedTypeNum;
    NSMutableDictionary *paramDic;
    NSMutableArray *TaizhangIdArr;
    
    NSMutableArray *OfficeArr;
    NSNumber *userId;
    NSString *MyvisitType;
    
    //日历
    UIView *datePickView;
    
    UILabel *Startweek;
    UILabel *Startyear;
    UILabel *Startmonth;
    UILabel *Endweek;
    UILabel *Endyear;
    UILabel *Endmonth;
    int butttag;
    
    UIButton *endButton;
    
    UIView *selectedButtonView;
    
    int Page;
    NSString *currentPage;
    NSString *currentNum;
    
    UIButton  *AddButton;
    
    NSString *searchStartDate;
    NSString *searchEndDate;
    
    //判断日历是否 滑动
    BOOL IsScrolled;
    
    int endtType;
    
    UIView *dateSelectedview;
    
    int time;
    int YearCount;
    int count;
    
    BOOL isGet;
}

@property (strong, nonatomic) UITableView *visitTableView;

@property (strong, nonatomic) UIButton *selectDayBtn;
@property (strong, nonatomic) UIButton *selectWeekBtn;
@property (strong, nonatomic) UIButton *selectMonBtn;
@property (strong, nonatomic) UIButton *selectAllBtn;

@property (nonatomic, assign) NSInteger manageViewNum;
@property (strong, nonatomic) UIView *statisticsView;//人员统计
@property (strong, nonatomic) UIView *areaVisitView;//辖区拜访
@property (strong, nonatomic) UITableView *statisticsTableView;//人员统计
@property (strong, nonatomic) UITableView *areaVisitTableView;//辖区拜访
@property (strong, nonatomic) UISegmentedControl *segment;

@property (nonatomic, assign) NSInteger manageViewNum2;
@property (strong, nonatomic) UIView *statisticsView2;//办事处统计
@property (strong, nonatomic) UIView *allVisitView;//所有拜访
@property (strong, nonatomic) UITableView *statisticsTableView2;//人员统计
@property (strong, nonatomic) UITableView *allVisitTableView;//所有拜访
@property (strong, nonatomic) UISegmentedControl *segment2;


@property (strong, nonatomic) UIView *topView;
@property (strong, nonatomic) UIView *searchView;
@property (strong, nonatomic) UIButton *selectBtn;
@property (strong, nonatomic) UIButton *selectListBtn;
@property (strong, nonatomic) UITextField *searchFld;
@property (strong, nonatomic) UIButton *searchImgBtn;
@property (strong, nonatomic) UIView *searchListView;
@property (strong, nonatomic) UISearchBar *searchBar;
@property (nonatomic) BOOL isSearching;

@property (nonatomic, strong) NSString *month;
@property (nonatomic, strong) NSString *year;
@property (nonatomic, strong) NSDate   *date;

- (void)sideLeftButton_selector:(id)sender;

@end

@implementation VisitViewController

@synthesize revealController;
- (void)viewWillDisappear:(BOOL)animated
{
    time = 0;
    count = 0;
}
- (void)viewWillAppear:(BOOL)animated{
    [_tableView deselectRowAtIndexPath:[_tableView indexPathForSelectedRow] animated:YES];
    
}

- (void)clickToNewVisit{
    AddVisitViewController *newVisitViewController = [[AddVisitViewController alloc] init];
//    newVisitViewController.delegate = self;
    [self.navigationController pushViewController:newVisitViewController animated:YES];
}

- (void)drawAddBtn{
    AddButton = [ViewTool getAddButtonWithTarget:self WithString:@"add.png" WithAction:@selector(clickToNewVisit)];
    [self.view addSubview:AddButton];
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = GrayBackColor;

    Page = 1;
    endtType = 1;
    SelectedType = @"all";
    selectedTypeNum = 0;
    currentPage = @"1";
    
    YearCount = CHOOSE_YEAR_COUNT;
    
    int useId = [[[NSUserDefaults standardUserDefaults] objectForKey:@"userId"] intValue];
    userId = [NSNumber numberWithInt:useId];

    [ViewTool setNavigationBar:self.navigationController.navigationBar];
    
    self.navigationItem.title = @"拜访管理";
    
    mineArray  = [NSMutableArray array];
    expandArray = [NSMutableArray array];
    visitListArray = [NSMutableArray array];
    TaizhangIdArr = [NSMutableArray array];
    OfficeArr = [NSMutableArray array];
    
    [SideMenuUtil addViewGesture:self revealController:revealController];
    
    righB = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, Height(20), Height(20))];
    righB.hidden = YES;
    [righB setBackgroundImage:[UIImage imageNamed:@"search.png"] forState:UIControlStateNormal];
    [righB addTarget:self action:@selector(clickSearch:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *barbtn = [[UIBarButtonItem alloc] initWithCustomView:righB];
    self.navigationItem.rightBarButtonItem = barbtn;
    
    self.navigationItem.leftBarButtonItem=[ViewTool getListBarButtonItemWithTarget:self WithAction:@selector(sideLeftButton_selector:)];
    
    int roleID = [[[NSUserDefaults standardUserDefaults] objectForKey:@"roleId"] intValue];
    if (roleID == 4) {
        role =0 ;
    }else if (roleID == 2){
        role = 1 ;
    }else if(roleID == 1){
        role = 2;
    }
    //    role = 0; //0 是商务经理 1 城市总监 2管理者
    if (role == 0) {
        type = 1;
    }
    if (role == 1) {
        type = 1;//暂时现请求辖区数据 只有辖区小区的数据
    }
    if(role == 2){
        type = 1;
    }
    
    [self createCalendar];
    
    [self addTopBtnView];
    [self creatButton];
    [self addTableview];
    [self createSearchView];
}
#pragma mark --顶上的按钮
- (void)addTopBtnView
{
    btnView = [[ManagerNoticeBtnView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 38)];
    if (role == 0) {//高级经理
        btnView.btnTitleArray = @[@"我的拜访"];
    }else if(role == 1){//城市总监
        btnView.btnTitleArray = @[@"人员统计",@"辖区拜访"];
    }else if(role == 2){ //管理者
        btnView.btnTitleArray = @[@"办事处统计",@"所有拜访"];
    }
    btnView.backgroundColor = BlueColor;
    btnView.delegate = self;
    btnView.titleColor = [UIColor whiteColor];
    [self.view addSubview:btnView];
    if (role != 0) {
        dateSelectedview = [[UIView alloc] initWithFrame:CGRectMake(0, btnView.maxY, kScreenWidth, 195)];
        dateSelectedview.backgroundColor = [UIColor whiteColor];
        [self.view addSubview:dateSelectedview];
        
        UIButton *DatePickButt = [[UIButton alloc] initWithFrame:CGRectMake(kScreenWidth/2.0-Width(40), 5, Width(80), 30)];
        [DatePickButt setTitle:@"日期选择" forState:UIControlStateNormal];
        [DatePickButt setTitleColor:GRAYCOLOR forState:UIControlStateNormal];
        DatePickButt.titleLabel.textAlignment = NSTextAlignmentCenter;
        [dateSelectedview addSubview:DatePickButt];
        //获取当天所在的 年 月 日 星期
        NSDate *now = [NSDate date];
        NSCalendar *calendar = [NSCalendar currentCalendar];
        NSUInteger unitFlags = NSDayCalendarUnit|NSMonthCalendarUnit|NSYearCalendarUnit;
        NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:now];
        NSDateFormatter *inputFormatter= [[NSDateFormatter alloc] init];
        [inputFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"zh"]];
        inputFormatter.dateFormat = @"EE";
        
        NSString * week = [inputFormatter stringFromDate: [NSDate date]];
        NSString *day = [NSString stringWithFormat:@"%d",(int)[dateComponent day]];
        if ([day intValue] < 10) {
            day = [NSString stringWithFormat:@"0%d",(int)[dateComponent day]];
        }
        
        NSString *month = [NSString stringWithFormat:@"%d",(int)[dateComponent month]];
        if ([month intValue] < 10) {
            month = [NSString stringWithFormat:@"0%d",(int)[dateComponent month]];
        }
        NSString *year = [NSString stringWithFormat:@"%d",(int)[dateComponent year]];
        
        Startweek = [ViewTool getLabelWith:CGRectMake(DatePickButt.x - Width(65), DatePickButt.maxY+3, Width(30), 30) WithTitle:week WithFontSize:14 WithTitleColor:GRAYCOLOR WithTextAlignment:NSTextAlignmentLeft];
        Startmonth = [ViewTool getLabelWith:CGRectMake(Startweek.x, Startweek.maxY, Width(100), 30) WithTitle:[NSString stringWithFormat:@"%@.%@",month,day] WithFontSize:26 WithTitleColor:UIColorFromRGB(0xff7701) WithTextAlignment:NSTextAlignmentLeft];
        Startyear = [ViewTool getLabelWith:CGRectMake(Startweek.x+10, Startmonth.maxY, Width(80), 30) WithTitle:year WithFontSize:14 WithTitleColor:BLACKCOLOR WithTextAlignment:NSTextAlignmentLeft];
        
        UIImageView *dateImage = [[UIImageView alloc] initWithFrame:CGRectMake(kScreenWidth/2.0-12, Startmonth.y, 24, 24)];
        dateImage.image = [UIImage imageNamed:@"Btn_Normal_Riqi"];
        [dateSelectedview addSubview:dateImage];
        
        Endweek = [ViewTool getLabelWith:CGRectMake(DatePickButt.maxX + Width(10), DatePickButt.maxY+3, Width(30), 30) WithTitle:week WithFontSize:14 WithTitleColor:GRAYCOLOR WithTextAlignment:NSTextAlignmentLeft];
        Endmonth = [ViewTool getLabelWith:CGRectMake(Endweek.x, Endweek.maxY, Width(100), 30) WithTitle:[NSString stringWithFormat:@"%@.%@",month,day] WithFontSize:26 WithTitleColor:UIColorFromRGB(0xff7701) WithTextAlignment:NSTextAlignmentLeft];
        Endyear = [ViewTool getLabelWith:CGRectMake(Endweek.x+10, Endmonth.maxY, Width(80), 30) WithTitle:year WithFontSize:14 WithTitleColor:BLACKCOLOR WithTextAlignment:NSTextAlignmentLeft];
        searchStartDate = [NSString stringWithFormat:@"%@-%@-%@",year,month,day];
        searchEndDate = [NSString stringWithFormat:@"%@-%@-%@",year,month,day];
        
        WeekString = week;
        dayString = day;
        monthString = month;
        yearString = year;
        
        [dateSelectedview addSubview:Startweek];
        [dateSelectedview addSubview:Startmonth];
        [dateSelectedview addSubview:Startyear];
        
        [dateSelectedview addSubview:Endweek];
        [dateSelectedview addSubview:Endmonth];
        [dateSelectedview addSubview:Endyear];
        
        UIButton *startButt = [[UIButton alloc] initWithFrame:CGRectMake(Startweek.x, Startweek.y, Width(50), Height(90))];
        startButt.tag = 0;
        [startButt addTarget:self action:@selector(DatepickViewShow:) forControlEvents:UIControlEventTouchUpInside];
        [dateSelectedview addSubview:startButt];
        
        UIButton *endButt = [[UIButton alloc] initWithFrame:CGRectMake(Endweek.x, Startweek.y, Width(50), Height(90))];
        endButt.tag = 1;
        [endButt addTarget:self action:@selector(DatepickViewShow:) forControlEvents:UIControlEventTouchUpInside];
        [dateSelectedview addSubview:endButt];
            
        [self CreatLine:self.view Y:180];
    }
    
}

- (void)creatButton
{
    selectedButtonView = [[UIView alloc] initWithFrame:CGRectMake(0, btnView.maxY, kScreenWidth, 60.0f)];
    selectedButtonView.backgroundColor = UIColorFromRGB(0xffffff);
    [self.view addSubview:selectedButtonView];
    [self.view sendSubviewToBack:selectedButtonView];
    
    NSArray *titleArr = @[@"全部",@"当日",@"本周",@"本月"];
    for (int i = 0; i< titleArr.count; i++) {
        UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(20 + ((kScreenWidth-40)/titleArr.count)*i, 5, (kScreenWidth-40)/titleArr.count, 60 - 10 )];
        [btn setTitle:titleArr[i] forState:UIControlStateNormal];
        btn.tag = i;
        btn.titleLabel.font = [ViewTool getFont:15.0f];;
        if (i == 0) {
            [btn setBackgroundImage:[UIImage imageNamed:@"Btn_Normal_Yishenpi"] forState:UIControlStateNormal];
            btn.selected = YES;
            btn.enabled = NO;
            endButton = btn;
            [btn setTitleColor:UIColorFromRGB(0xff7703) forState:UIControlStateNormal];
        }else{
            btn.selected = NO;
            [btn setTitleColor:[UIColor colorWithWhite:0.7 alpha:1] forState:UIControlStateNormal];
        }
        
        [selectedButtonView addSubview:btn];
        [btn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
    }
    
    [self CreatLine:selectedButtonView Y:60];
}
- (void)CreatLine:(UIView *)view Y:(float)y
{
    UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, y, self.view.width, 15.0f)];
    backView.backgroundColor = UIColorFromRGB(0xf8f8fa);
    UIView *line1 = [ViewTool getLineViewWith:CGRectMake(0, 0, kScreenWidth, 1) withBackgroudColor:UIColorFromRGB(0xe6e7eb)];
    [backView addSubview:line1];
    
    UIView *line2 = [ViewTool getLineViewWith:CGRectMake(0, 14, kScreenWidth, 1) withBackgroudColor:UIColorFromRGB(0xe6e7eb)];
    [backView addSubview:line2];
    [view addSubview:backView];
}
- (void)clickBtn:(UIButton *)btn
{
    if (endButton != btn) {
        [endButton setBackgroundImage:nil forState:UIControlStateNormal];
        [endButton setTitleColor:[UIColor colorWithWhite:0.7 alpha:1] forState:UIControlStateNormal];
        endButton.selected = NO;
        endButton.enabled = YES;
        btn.enabled = NO;
        [btn setBackgroundImage:[UIImage imageNamed:@"Btn_Normal_Yishenpi"] forState:UIControlStateNormal];
        [btn setTitleColor:UIColorFromRGB(0xff7703) forState:UIControlStateNormal];
        btn.selected = YES;
        endButton = btn;
        
    }
    if (btn.tag == 0) {
        SelectedType = @"all";
    }else if (btn.tag == 1){
        SelectedType = @"today";
    }
    else if (btn.tag == 2){
        SelectedType = @"week";
    }
    else if (btn.tag == 3){
        SelectedType = @"month";
    }
    selectedTypeNum = (int)btn.tag;
    [SVProgressHUD showWithStatus:@"加载中"];
    [self loadNewData];
    [self.view bringSubviewToFront:_topView];
}

- (void)DatepickViewShow:(UIButton *)butt
{
    butttag = (int)butt.tag;
    
    [self.view bringSubviewToFront:datePickView];
}
- (void)showSearchView{
    
    if (_topView.hidden) {
        _topView.hidden = NO;
        _searchListView.hidden = YES;
    }else{
        _topView.hidden = YES;
        _searchListView.hidden = YES;
    }
}

- (void)showSelectList:(UIButton *)button{
    
}

- (void)hideSearchBtn{
    
}

- (UIButton *)getButtonWithFrame:(CGRect)frame withTitle:(NSString *)title {
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = frame;
    [button setTitle:title forState:UIControlStateNormal];
    
    button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;//左对齐
    
    [button setTitleColor:UIColorFromRGB(0xa1a2a7) forState:UIControlStateNormal];
    button.titleLabel.font= [UIFont systemFontOfSize:16.0f];
    return button;
}

//创建头部视图
-(void)createSearchView
{
    CGFloat searchViewHight = 60.0f;
    
    _topView = [[UIView alloc] initWithFrame:CGRectMake(0, btnView.maxY, kScreenWidth, searchViewHight)];
    [self.view addSubview:_topView];
    [self.view sendSubviewToBack:_topView];
    
    UIView *searchView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, searchViewHight)];
    [searchView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"Btn_Normal_Sousuodi.png"]]];
    
    UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 10, kScreenWidth-40, searchView.height-20)];
    imgView.image = [UIImage imageNamed:@"Btn_Normal_Sousuokuang.png"];
    
    _searchFld = [[UITextField alloc] initWithFrame:CGRectMake(imgView.x+10,imgView.y,imgView.width,imgView.height)];
    _searchFld.placeholder = @"时间/小区名称/网点编号";
    _searchFld.delegate = self;
    _searchFld.returnKeyType = UIReturnKeySearch;
    [_searchFld setValue:LEFTLINECOLOR forKeyPath:@"_placeholderLabel.textColor"];
    [_searchFld setValue:[UIFont systemFontOfSize:16.0f] forKeyPath:@"_placeholderLabel.font"];
    
    
    UIImageView *bgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, _searchListView.width, _searchListView.height)];
    bgView.image = [UIImage imageNamed:@"Btn_Normal_Shaixuan.png"];
    
    [searchView addSubview:imgView];
    [searchView addSubview:_searchFld];
    [searchView addSubview:_searchImgBtn];
    
    [_searchListView addSubview:bgView];
    
    [_topView addSubview:searchView];
    
    [_topView addSubview:_searchListView];
    _topView.hidden = YES;
    
}
//点击搜索框中的搜索
- (void)SearchButton
{
    [TaizhangIdArr removeAllObjects];
    [expandArray removeAllObjects];
    [SVProgressHUD showWithStatus:@"搜索中"];
    [self getVisitListByType:SelectedType page:currentPage pageNum:@"10" search:_searchFld.text];
    
}
- (void)changeNoticeView:(NSInteger)tag
{
    for (int i = 0; i < btnView.btnTitleArray.count; i++) {
        TopBtn *btn = [btnView viewWithTag:9966 + i];
        
        if (tag == 9966 + i) {
            btn.lineView.backgroundColor = YELLOWBTNCOLOR;
        }else{
            btn.lineView.backgroundColor = BlueColor;
        }
    }
    if (role == 0) {
        //高级经理
        if (tag == 9966) {
            type = 1;
            _newSubdistrictBtn.hidden = NO;
            righB.hidden = NO;
        }else if(tag == 9967){
            type = 2;
            _newSubdistrictBtn.hidden = YES;
            righB.hidden = YES;
            
        }else{
            type = 3;
            _newSubdistrictBtn.hidden = YES;
            righB.hidden = YES;
        }
        
        [self loadCityDataWithSeachText:nil];
    }else if(role == 1){//城市总监
        if (tag == 9966) {
            type = 1;
            righB.hidden = YES;
            [self.view sendSubviewToBack:_topView];
            _newSubdistrictBtn.hidden = YES;
            [self.view sendSubviewToBack:AddButton];
            _tableView.mj_header.hidden = YES;
            _tableView.mj_footer = nil;
            [_searchFld resignFirstResponder];
        }else{
            _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
                [self loadNewData];
            }];
            
            _tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    [self loadMoreData];
                });
            }];
            type = 2;
            righB.hidden = NO;
            if (isGet == YES) {
                _topView.hidden = NO;
                selectedButtonView.frame = CGRectMake(0, btnView.maxY + _topView.height, kScreenWidth, 60.0f);
                _tableView.frame = CGRectMake(0, selectedButtonView.height + btnView.height + 15 + _topView.height, kScreenWidth,kScreenHeight - selectedButtonView.height - btnView.height - 15 -_topView.height -64);
                righB.selected = YES;
            }else{
                
                _topView.hidden = YES;
                selectedButtonView.frame = CGRectMake(0, btnView.maxY, kScreenWidth, 60.0f);
                _tableView.frame = CGRectMake(0, selectedButtonView.height + btnView.height + 15, kScreenWidth, kScreenHeight - selectedButtonView.height - btnView.height - 15 -64);
                righB.selected = NO;
            }
            
            [self.view bringSubviewToFront:_topView];
            _newSubdistrictBtn.hidden = NO;
            [self.view bringSubviewToFront:AddButton];
        }
    }else if(role == 2){//管理者
        if (tag == 9966) {
            type = 1;
            righB.hidden = YES;
            [self.view sendSubviewToBack:_topView];
            _newSubdistrictBtn.hidden = YES;
            [self.view sendSubviewToBack:AddButton];
            _tableView.mj_header.hidden = YES;
            _tableView.mj_footer = nil;
            [_searchFld resignFirstResponder];
        }else{
            type = 2;
            _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
                [self loadNewData];
            }];
            
            _tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    [self loadMoreData];
                });
            }];
            righB.hidden = NO;
            
            if (isGet == YES) {
                _topView.hidden = NO;
                selectedButtonView.frame = CGRectMake(0, btnView.maxY + _topView.height , kScreenWidth, 60.0f);
                _tableView.frame = CGRectMake(0, selectedButtonView.height + btnView.height + 15 + _topView.height, kScreenWidth,kScreenHeight - selectedButtonView.height - btnView.height - 15 -_topView.height -64);
                righB.selected = YES;
                
            }else{
                
                _topView.hidden = YES;
                selectedButtonView.frame = CGRectMake(0, btnView.maxY, kScreenWidth, 60.0f);
                _tableView.frame = CGRectMake(0, selectedButtonView.height + btnView.height + 15, kScreenWidth, kScreenHeight - selectedButtonView.height - btnView.height - 15 -64);
                righB.selected = NO;
                
            }

            [self.view bringSubviewToFront:_topView];
            _newSubdistrictBtn.hidden = NO;
            [self.view sendSubviewToBack:AddButton];
        }
    }
    if (endtType == type) {
        return;
    }
    if (type == 1) {
        dateSelectedview.alpha = 1;
    }else{
        dateSelectedview.alpha = 0;
    }

    time++;
    if (time == 1) {
        [SVProgressHUD showWithStatus:@"加载中"];
        [self loadNewData];
        endtType = type;
    }
    
        _tableView.tag = type;
    if (type == 1) {
        [self.view sendSubviewToBack:selectedButtonView];

        _tableView.frame = CGRectMake(0, 195, kScreenWidth, kScreenHeight-btnView.height-195-64+btnView.height);

    }else if (type == 2){
       
        [self.view bringSubviewToFront:selectedButtonView];
        [self.view bringSubviewToFront:_topView];
        
    }
        [_tableView reloadData];
        NSLog(@"xcacacac %d",(int)_tableView.tag);
        endtType = type;
    
}

#pragma mark --搜索框
- (void)clickSearch:(UIButton *)btn
{
    if (type == 2) {
        if (btn.selected == NO) {
           isGet = YES;
            _topView.hidden = NO;
            selectedButtonView.frame = CGRectMake(0, btnView.maxY + _topView.height, kScreenWidth, 60.0f);
            _tableView.frame = CGRectMake(0, selectedButtonView.height + btnView.height + 15 + _topView.height, kScreenWidth,kScreenHeight - selectedButtonView.height - btnView.height - 15 - _topView.height -64);
            
        }else{
            isGet = NO;
            _topView.hidden = YES;
            _searchFld.text = @"";
            selectedButtonView.frame = CGRectMake(0, btnView.maxY, kScreenWidth, 60.0f);
            _tableView.frame = CGRectMake(0, selectedButtonView.height + btnView.height + 15, kScreenWidth, kScreenHeight - selectedButtonView.height - btnView.height - 15 -64);
        }
        btn.selected = !btn.selected;
    }
}
#pragma mark textfield 搜索
- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
    if (theTextField == _searchFld) {
        [theTextField resignFirstResponder];
    }
    [self search];
    
    return YES;
}

- (void)search{
    
    if (_searchFld.text == nil || _searchFld.text.length == 0) {
        [Tools showMessage:@"请输入搜索关键字" view:self];
        return;
    }
    currentPage = @"1";
    
    [_searchFld resignFirstResponder];
    [TaizhangIdArr removeAllObjects];
    [expandArray removeAllObjects];
    [SVProgressHUD showWithStatus:@"搜索中"];
    [self getVisitListByType:SelectedType page:currentPage pageNum:@"10" search:_searchFld.text];
}

#pragma mark --Calendar
- (void)createCalendar
{
    datePickView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    
    [self.view addSubview:datePickView];
    UIView *BGview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight*2/3.0-64)];
    BGview.backgroundColor = [UIColor blackColor];
    BGview.alpha = 0.6;
    [datePickView addSubview:BGview];
    
    UIView *DownBgview = [[UIView alloc] initWithFrame:CGRectMake(0, BGview.maxY, kScreenWidth, kScreenHeight/3.0)];
    DownBgview.backgroundColor = [UIColor whiteColor];
    [datePickView addSubview:DownBgview];
    
    UIButton *yesButton = [[UIButton alloc] initWithFrame:CGRectMake(kScreenWidth - 60, 5, 42, 30)];
    [yesButton setImage:[UIImage imageNamed:@"Btn_Normal_Queding"] forState:UIControlStateNormal];
    yesButton.tag = 0;
    [yesButton addTarget:self action:@selector(ButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [DownBgview addSubview:yesButton];
    
    UIButton *noButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 5, 42, 30)];
    [noButton setImage:[UIImage imageNamed:@"Btn_Normal_Quxiao"] forState:UIControlStateNormal];
    noButton.tag = 1;
    [noButton addTarget:self action:@selector(ButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [DownBgview addSubview:noButton];
    
    UILabel *upXian = [[UILabel alloc] initWithFrame:CGRectMake(noButton.x, noButton.maxY, kScreenWidth, 1)];
    upXian.backgroundColor = GRAYLINECOLOR;
    [DownBgview addSubview:upXian];
    
    HYMDatePicker *datePick = [[HYMDatePicker alloc] init];
    datePick.frame = CGRectMake(0, upXian.maxY+10, kScreenWidth, kScreenHeight/3.0-60);
    datePick.delegateDiy = self;
    
    [datePick selectRow:YearCount inComponent:0 animated:NO];
    NSDate *now = [NSDate date];
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSUInteger unitFlags = NSDayCalendarUnit|NSMonthCalendarUnit;
    NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:now];
    int day = (int)[dateComponent day];
    int month = (int)[dateComponent month];
    
    [datePick selectRow:YearCount-1 inComponent:0 animated:NO];
    [datePick selectRow:month-1 inComponent:1 animated:NO];
    [datePick selectRow:day-1 inComponent:2 animated:NO];
    
    [DownBgview addSubview:datePick];
    
}
- (void)ButtonClick:(UIButton *)butt
{
    if (IsScrolled == NO) {
        if (butt.tag == 1) {
            [self.view sendSubviewToBack:datePickView];
            return;
        }else{
            if (butttag == 0) {
                [self datepickstart];
                
            }else if (butttag == 1){
                [self datepickend];
            }
            if (role == 2) {
                [self loadDataWithSearchText:nil];
            }else if (role == 1){
                [self loadNewData];
            }
        }
        return;
    }
    
    if (butt.tag == 0) {
        if (butttag == 0) {
            NSArray *endArr = [Endmonth.text componentsSeparatedByString:@"."];
            int endM = [[endArr objectAtIndex:0] intValue];
            int endD = [[endArr objectAtIndex:1] intValue];
            
            if ([yearString intValue] > [Endyear.text intValue]) {
                [Tools showMessage:@"起始日期不能大于结束日期" view:self];
                return;
            }
            if ([yearString intValue] == [Endyear.text intValue]){
                if ([monthString intValue] > endM) {
                    [Tools showMessage:@"起始日期不能大于结束日期" view:self];
                    return;
                }
                if ([monthString intValue] == endM){
                    if ([dayString intValue] > endD) {
                        [Tools showMessage:@"起始日期不能大于结束日期" view:self];
                        return;
                    }
                }
            }
            [self datepickstart];
        }
        else{
            NSArray *startArr = [Startmonth.text componentsSeparatedByString:@"."];
            int startM = [[startArr objectAtIndex:0] intValue];
            int startD = [[startArr objectAtIndex:1] intValue];
            
            if ([yearString intValue] < [Startyear.text intValue]) {
                [Tools showMessage:@"结束日期不能小于起始日期" view:self];
                return;
            }
            if ([yearString intValue] == [Startyear.text intValue]){
                if ([monthString intValue] < startM) {
                    [Tools showMessage:@"结束日期不能小于起始日期" view:self];
                    return;
                }
                if ([monthString intValue] == startM){
                    if ([dayString intValue] < startD) {
                        [Tools showMessage:@"结束日期不能小于起始日期" view:self];
                        return;
                    }
                }
            }
            [self datepickend];        }
        count ++;
        
        if (role == 2) {
            [self loadDataWithSearchText:nil];
        }else if (role == 1){
            [self loadNewData];
        }
        IsScrolled = NO;
    }
    else if (butt.tag == 1)
    {
        [self.view sendSubviewToBack:datePickView];
    }
}
- (void)datepickstart
{
    Startweek.text = WeekString;
    Startmonth.text = [NSString stringWithFormat:@"%@.%@",monthString,dayString];
    Startyear.text = yearString;
    searchStartDate = [NSString stringWithFormat:@"%@-%@-%@",yearString,monthString,dayString];
    [self.view sendSubviewToBack:datePickView];
}
- (void)datepickend
{
    Endweek.text = WeekString;
    Endmonth.text = [NSString stringWithFormat:@"%@.%@",monthString,dayString];
    Endyear.text = yearString;
    searchEndDate = [NSString stringWithFormat:@"%@-%@-%@",yearString,monthString,dayString];
    [self.view sendSubviewToBack:datePickView];
}

//获取 日历当前滚动到的日期
- (void)currentSelectedDate:(NSString *)yearStr month:(NSString *)monthStr day:(NSString *)dayStr{
    
    IsScrolled = YES;
    
    NSString *dateStr = [NSString stringWithFormat:@"%@%@%@",yearStr,monthStr,dayStr];
    
    NSDateFormatter *inputFormatter= [[NSDateFormatter alloc] init];
    
    [inputFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"zh"]];
    
    [inputFormatter setDateFormat:@"yyyyMMdd"];
    
    NSDate*inputDate = [inputFormatter dateFromString:dateStr];
    
    NSLog(@"date= %@", inputDate);
    
    inputFormatter.dateFormat = @"EE";
    NSString * weekString = [inputFormatter stringFromDate: inputDate];
    yearString = yearStr;
    monthString = monthStr;
    dayString = dayStr;
    WeekString = weekString;
    
    NSLog(@"选中的时间 %@%@%@%@",yearStr,monthStr,dayStr,weekString);
    
}

#pragma mark --tableview
- (void)addTableview
{
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, selectedButtonView.height + 15 + btnView.height, kScreenWidth, kScreenHeight-selectedButtonView.height - btnView.height - 15) style:UITableViewStylePlain];
    _tableView.showsVerticalScrollIndicator = NO;
    _tableView.tag = type;
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.backgroundColor = GrayBackColor;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:_tableView];
    [SVProgressHUD show];
    [self loadNewData];
}

- (void)loadNewData
{
    currentPage = [NSString stringWithFormat:@"%d",1];
    if (role == 0) {
        //高级经理
        [self loadCityDataWithSeachText:nil];
    }else if(role == 1){
        //城市总监
        if (type == 1) {
            [OfficeArr removeAllObjects];
        }
        else{
            [TaizhangIdArr removeAllObjects];
            [expandArray removeAllObjects];
        }
        [self loadAdminDataWithSeachText:nil];
    }else if(role == 2){
        //管理者
        if (type == 1) {
            [OfficeArr removeAllObjects];
        }
        else{
            [TaizhangIdArr removeAllObjects];
            [expandArray removeAllObjects];
        }

        [self loadDataWithSearchText:nil];
    }
}

- (void)loadMoreData
{
    Page++;
    currentPage = [NSString stringWithFormat:@"%d",Page];
    if (role == 0) {
        //高级经理
        
    }else if(role == 1){
        //城市总监
        [self loadAdminDataWithSeachText:_searchFld.text];
        
    }else if(role == 2){
        //管理者
        [self loadDataWithSearchText:_searchFld.text];
    }

}


#pragma mark --请求数据
//城市总监
- (void)loadAdminDataWithSeachText:(NSString *)searchText
{
    if (type == 1) {

        [self.view sendSubviewToBack:selectedButtonView];
        [_tableView reloadData];
        _tableView.frame = CGRectMake(0, 195, kScreenWidth, kScreenHeight-btnView.height-195-64+btnView.height);
        NSString *timearea = [NSString stringWithFormat:@"1990-01-01,%@",searchEndDate];
        NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:@{@"method":@"app.visit.count.user",@"user_id":userId,@"timearea":timearea}];
        if (count != 0) {
            timearea = [NSString stringWithFormat:@"%@,%@",searchStartDate,searchEndDate];
            [dict setObject:timearea forKey:@"timearea"];
        }
        
        NSDictionary *paramersDict = [DataTool addSignToDic:dict];
        NSLog(@"城市中间  参数： %@",paramersDict);
        [DataTool postWithUrl:HEAD_URL parameters:paramersDict success:^(id data) {
            [SVProgressHUD dismiss];
            id backData = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments | NSJSONReadingMutableContainers error:nil];
            NSLog(@"办事处人员统计的数据%@",backData);
            NSString *status = [(NSDictionary *)backData objectForKey:@"status"];
            
         if ([status isEqualToString:@"SUCCESS"]) {
            NSArray *dataArray = backData[@"data"];
             if (dataArray.count == 0){
                 [Tools showMessage:@"数据为空" view:self];
             }
             

            for (int i = 0; i< dataArray.count; i++) {
                OfficeModel *model = [[OfficeModel alloc] init];
                [model setValuesForKeysWithDictionary:dataArray[i]];
                [OfficeArr addObject:model];
            }
          }
         else {
             int code = [[(NSDictionary *)backData objectForKey:@"code"] intValue];
             NSString *msg = [(NSDictionary *)backData objectForKey:@"msg"];
             NSLog(@"办事处人员统计返回%@%d%@",status,code,msg);
             [Tools showMessage:msg view:self];
         }
        [_tableView reloadData];
        } fail:^(NSError *error) {
            [SVProgressHUD dismiss];
            [Tools showMessage:error.localizedDescription view:self];
            NSLog(@"%@",error.localizedDescription);
        }];
        
       
    }else if(type == 2){

        [_tableView reloadData];
        [self getVisitListByType:SelectedType page:currentPage pageNum:@"10" search:_searchFld.text];
    }
}

- (void)getVisitListByType:(NSString *)Type page:(NSString *)page pageNum:(NSString *)pageNum search:(NSString *)searchText
{

    NSNumber *pageN = [NSNumber numberWithUnsignedLong:[page longLongValue]];
    NSNumber *pageN2 = [NSNumber numberWithUnsignedLong:[pageNum longLongValue]];
    NSString *method = [NSString string];
    
    if (role == 1) {
        method = @"app.visit.area.list";
    }else if (role == 2){
        method = @"app.visit.all.list";
    }
    if ([_searchFld.text isEqualToString:@""] || _topView.hidden == YES) {
        paramDic = [NSMutableDictionary dictionaryWithDictionary:@{@"method":method,@"type":Type,@"page":pageN,@"pageNum":pageN2,@"user_id":userId}];
    }
    else{
        paramDic = [NSMutableDictionary dictionaryWithDictionary:@{@"method":method,@"type":Type,@"page":pageN,@"pageNum":pageN2,@"search":searchText,@"user_id":userId}];
    }

    NSDictionary *paramersDict = [DataTool addSignToDic:paramDic];
    [DataTool postWithUrl:HEAD_URL parameters:paramersDict success:^(id data) {
        [SVProgressHUD dismiss];
        
        for (int i = 0; i< 4; i++) {
            
            UIButton *myButton = (UIButton *)[selectedButtonView viewWithTag:i];
            myButton.userInteractionEnabled = YES;
        }
        

        id backData = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments | NSJSONReadingMutableContainers error:nil];
        NSLog(@"辖区拜访的数据%@",backData);
        
        NSString *status = [(NSDictionary *)backData objectForKey:@"status"];
        
        if ([status isEqualToString:@"SUCCESS"]) {

        NSArray *dataArray = backData[@"data"][@"listData"];
         int total = [backData[@"data"][@"total"] intValue];
        if (total != NSNotFound){
        if (total== 0) {
            [Tools showMessage:@"数据为空" view:self];
           }
        }

        for (int i = 0; i< dataArray.count; i++) {
            VisitModel *model = [[VisitModel alloc] init];
            [model setValuesForKeysWithDictionary:dataArray[i]];
            [expandArray addObject:model];
        }
        if (total < 10) {
            [_tableView.mj_footer endRefreshingWithNoMoreData];
        }else{
            if (dataArray.count < 10) {
                [_tableView.mj_footer endRefreshingWithNoMoreData];
            }else{
                [_tableView.mj_footer endRefreshing];
            }
        }
        }else{
            int code = [[(NSDictionary *)backData objectForKey:@"code"] intValue];
            NSString *msg = [(NSDictionary *)backData objectForKey:@"msg"];
            NSLog(@"拜访返回%@%d%@",status,code,msg);
            [Tools showMessage:msg view:self];
            if (code == 999991) {
                [_tableView.mj_footer endRefreshingWithNoMoreData];
            }else{
               [_tableView.mj_footer endRefreshing]; 
            }
        }
        [_tableView reloadData];
        [_tableView.mj_header endRefreshing];
        
    } fail:^(NSError *error) {
        [SVProgressHUD dismiss];
        [Tools showMessage:error.localizedDescription view:self];
        [_tableView.mj_footer endRefreshingWithNoMoreData];
        [_tableView.mj_header endRefreshing];
        NSLog(@"%@",error.localizedDescription);
    }];
    
}
//高级经理
- (void)loadCityDataWithSeachText:(NSString *)searchText
{
    if (type == 1) {
        [_tableView reloadData];
        _tableView.frame = CGRectMake(0, 195, kScreenWidth, kScreenHeight-btnView.height-195-64+btnView.height);
        
        NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:@{@"method":@"app.visit.my.visit",@"user_id":userId,@"type":MyvisitType}];
        [OfficeArr removeAllObjects];
        NSDictionary *paramersDict = [DataTool addSignToDic:dict];
        [DataTool postWithUrl:HEAD_URL parameters:paramersDict success:^(id data) {
            id backData = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments | NSJSONReadingMutableContainers error:nil];
            NSArray *dataArray = backData[@"data"][@"listData"];
            NSString *total = backData[@"total"];
            if ([total isEqualToString:@"0"]) {
                [Tools showMessage:@"数据为空" view:self];
            }
            for (int i = 0; i< dataArray.count; i++) {
                OfficeModel *model = [[OfficeModel alloc] init];
                [model setValuesForKeysWithDictionary:dataArray[i]];
                [OfficeArr addObject:model];
            }
            [_tableView reloadData];
            [_tableView.mj_header endRefreshing];
            [SVProgressHUD dismiss];
        } fail:^(NSError *error) {
            NSLog(@"%@",error.localizedDescription);
            [_tableView.mj_header endRefreshing];
            [SVProgressHUD dismiss];
        }];
    }
}
//管理者
- (void)loadDataWithSearchText:(NSString *)searchText
{
    if (type == 1) {

        [self.view sendSubviewToBack:selectedButtonView];
        [_tableView reloadData];
        
        _tableView.frame = CGRectMake(0, 195, kScreenWidth, kScreenHeight-btnView.height-195-64+btnView.height);
        NSString *timearea = [NSString stringWithFormat:@"1990-01-01,%@",searchEndDate];
        
        NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:@{@"method":@"app.visit.count.all.agency",@"user_id":userId,@"timearea":timearea}];
        
        if (count != 0) {
            timearea = [NSString stringWithFormat:@"%@,%@",searchStartDate,searchEndDate];
            [dict setObject:timearea forKey:@"timearea"];
        }
        NSDictionary *paramersDict = [DataTool addSignToDic:dict];
        [DataTool postWithUrl:HEAD_URL parameters:paramersDict success:^(id data) {
            [SVProgressHUD dismiss];
            id backData = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments | NSJSONReadingMutableContainers error:nil];
           
            NSString *status = [(NSDictionary *)backData objectForKey:@"status"];
            
            if ([status isEqualToString:@"SUCCESS"]) {
                
            NSArray *dataArray = backData[@"data"];
            NSString *total = backData[@"total"];
            if ([total isEqualToString:@"0"]) {
                [Tools showMessage:@"数据为空" view:self];
            }
            for (int i = 0; i< dataArray.count; i++) {
                            OfficeModel *model = [[OfficeModel alloc] init];
                            [model setValuesForKeysWithDictionary:dataArray[i]];
                            [OfficeArr addObject:model];
            }
            

            }else{
                int code = [[(NSDictionary *)backData objectForKey:@"code"] intValue];
                NSString *msg = [(NSDictionary *)backData objectForKey:@"msg"];
                [Tools showMessage:msg view:self];
            }
            [_tableView reloadData];
        } fail:^(NSError *error) {
            [SVProgressHUD dismiss];
            [Tools showMessage:error.localizedDescription view:self];
            NSLog(@"%@",error.localizedDescription);
        }];
    }else if(type == 2){
        _tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
            [self loadMoreData];
        }];

        [self.view bringSubviewToFront:selectedButtonView];
        [self.view bringSubviewToFront:_topView];
        [_tableView reloadData];
        [self getVisitListByType:SelectedType page:currentPage pageNum:@"10" search:_searchFld.text];
    }
}
#pragma mark --tableview代理
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (tableView.tag == 2){
       return expandArray.count;
    }
    return OfficeArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView.tag == 1) {
        OficeTableViewCell *cell = [OficeTableViewCell cellWithTableView:tableView];
        if (OfficeArr.count != 0) {
             cell.model = OfficeArr[indexPath.row];
        }
        if (role == 1) {
            cell.officelabel.text = @"拜访姓名:";
           cell.visitNameImg.image = [UIImage imageNamed:@"Btn_Normal_Jingzhengduishou"];
            
        }else if (role == 2){
            cell.officelabel.text = @"办事处名称:";
            cell.officelabel.width = 70.0f;
            cell.VisitNameLabel.x = cell.officelabel.maxX;
            cell.visitNameImg.image = [UIImage imageNamed:@"Btn_Normal_Banshichu"];
        }
        cell.NumberLabel.text = [NSString stringWithFormat:@"%d",(int)indexPath.row+1];
        cell.visitCountImg.image = [UIImage imageNamed:@"Btn_Normal_baifangcishu"];
        
        return cell;
    }else if (tableView.tag == 2)
    {
        static NSString *CellIdentifier = @"VisitListCell";
        VisitListCell2 *cell = (VisitListCell2 *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[VisitListCell2 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        }
        
        cell.selectionStyle = UITableViewCellSelectionStyleGray;
        if (expandArray.count != 0) {
            VisitModel *model = [expandArray objectAtIndex:indexPath.row];
            cell.visitNum.text=model.branch_no;
            cell.visitSub.text=[NSString stringWithFormat:@"小区:%@",model.complex];
            
            cell.visitPro.text = [NSString stringWithFormat:@"物业:%@",model.property];
            cell.visitDate.text = model.last_at;
        }
        
        return cell;
    }
    
    return nil;
}

//AddVisitViewController@protocol UIViewPassValueDelegate
- (void)passValue:(NSString *)value{
    NSLog(@"HOMEVC_passValue:%@",value);
    if ([value isEqualToString:@"SECCESS"]) {
        [_visitTableView.mj_header beginRefreshing];
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (tableView.tag == 1) {
        OfficeModel *model = OfficeArr[indexPath.row];
        if (role == 2) {
            PersonnelstatisticsViewControl *vc = [[PersonnelstatisticsViewControl alloc] init];
            vc.Title = model.agency_name;
            vc.districtID = model.DistrictID;
            [self.navigationController pushViewController:vc animated:YES];
        }
        else if (role == 1) {
            PersonnelViewController *vc = [[PersonnelViewController alloc] init];
            vc.Title = model.realname;
            vc.districtID = model.user_id;
            [self.navigationController pushViewController:vc animated:YES];
        }
        return;
    }
    
    VisitInfoViewController *detailVC = [[VisitInfoViewController alloc] init];
    detailVC.model = [expandArray objectAtIndex:indexPath.row];
    detailVC.delegate = self;
    [self.navigationController pushViewController:detailVC animated:YES];
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView.tag == 1) {
        return [OficeTableViewCell cellHeight];
    }
    return 95.0f;
}

// 拉开左侧:点击.
- (void)sideLeftButton_selector:(id)sender {
    
    [self.revealController toggleSidebar:!self.revealController.sidebarShowing duration:kGHRevealSidebarDefaultAnimationDuration];
}

@end
